package nl.weeaboo.sh.editor.area;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

public class RandomColors {

	private int palette[];
	
	private RandomColors(int palette[]) {
		this.palette = palette;
	}
	
	//Functions
	public static RandomColors fromImage() throws IOException {
		BufferedImage paletteImage = ImageIO.read(RandomColors.class.getResourceAsStream("palette.png"));
		
		int palette[] = new int[paletteImage.getWidth() * paletteImage.getHeight()];
		for (int n = 0; n < palette.length; n++) {
			palette[n] = paletteImage.getRGB(n % paletteImage.getWidth(), n / paletteImage.getHeight());
		}
		return new RandomColors(palette);
	}
	
	public Color get(Object o) {
		return new Color(palette[o.hashCode() % palette.length]);		
	}
	
	//Getters
	
	//Setters
}
